from django.contrib import admin
from goods import models
from celery_tasks.static_html.tasks import generate_static_list_search_html, generate_static_sku_detail_html
# Register your models here.


class GoodsAdmin(admin.ModelAdmin):

    list_display = ['id', 'name']

    # admin站点中点击保存,触发生成静态列表页
    def save_model(self, request, obj, form, change):

        # 实现更新操作
        obj.save()
        generate_static_list_search_html.delay()

    def delete_model(self, request, obj):

        # 点击删除,实现删除操作
        # obj.delete()
        # obj.is_delete()
        generate_static_list_search_html.delay()


class SKUAdmin(admin.ModelAdmin):

    def save_model(self, request, obj, form, change):

        obj.save()
        generate_static_sku_detail_html.delay(obj.id)



admin.site.register(models.Goods, GoodsAdmin)
admin.site.register(models.SKU, SKUAdmin)